//
//  YZMAlertView.m
//  YZMicroStock
//
//  Created by wangminhong on 16/3/21.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMAlertView.h"
#import <Masonry/Masonry.h>
#import "YZMControllerManager.h"
#import "MBProgressHUD+Utils.h"
#import "YZMUserService.h"
#import "NSNumber+Utils.h"
#import <DateTools/DateTools.h>
#import <BlocksKit/UIControl+BlocksKit.h>
#import "UILabel+Color.h"

static const float alert_view_margin_left = 20.0;

@interface YZMAlertView()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *footLabel;
@property (nonatomic, strong) UIButton *sureButton;
@property (nonatomic, strong) UIButton *cancelButton;

@end

@implementation YZMAlertView{
    
    BOOL _hasMoveFlag;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame: frame];
    
    if (self) {
        
        [self createObjects];
    }
    return self;
}

- (void)keyboardWasShow:(NSNotification *)notification{
    
    NSDictionary *info = [notification userInfo];
    
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    
    [self animationMoveUpWithKeyboardHeight:keyboardSize.height];
}

- (void)keyboardWasHide:(NSNotification *)notification{
    
    [self animationMoveDown];
}

#pragma mark -- Public Method

+ (YZMAlertView *)alertViewForRecommandWithContent:(NSString *)content{
    
    YZMAlertView *alertView = [YZMAlertView new];
    alertView.contentLabel.text = content;
    alertView.contentLabel.numberOfLines = 0;
    alertView.contentLabel.textAlignment = NSTextAlignmentCenter;
    alertView.contentLabel.textColor = [YZMAppStyle colorForBlackText];
    alertView.contentLabel.font = [YZMAppStyle largeSizeBoldFont];
    alertView.cancelButton.hidden = YES;
    
    return alertView;
}

+(YZMAlertView *)alertViewForClearAll{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=@"申请清算";
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *contentLabel1=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:contentLabel1];
    contentLabel1.numberOfLines=0;
    contentLabel1.text=@"尊敬的用户您好：\n\n您当前申请提前清算，请确认所有持仓都已卖出，如持仓中有股票，将无法完成清算请求，请先平仓后再操作！否则系统默认直接发起卖出指令，请慎重选择!";
    [contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleLabel1);
        make.top.mas_equalTo(line1.mas_bottom).offset(10);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(contentLabel1.mas_bottom).offset(10);
    }];
    
    return alertView;
}

+(YZMAlertView *)alertwithtitle:(NSString *)title withfirststring:(NSString *)firststring firstvalue:(NSNumber *)firstvalue secondstring:(NSString *)secondstring secondvalue:(NSNumber *)secondvalue thirdstring:(NSString *)thirdstring thirdvalue:(NSNumber *)thirdvalue{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firststring;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    UILabel *yuan = [YZMAppStyle labelWithMediumBlack];
    yuan.text = @"万元";
    yuan.textAlignment=NSTextAlignmentRight;
    [backView addSubview:yuan];
    [yuan mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(backView);
        make.centerY.equalTo(firstLabel);
        make.width.mas_equalTo(35);
    }];
    
    alertView.addmoneyTextfield=[YZMAppStyle inputTextField];
    [backView addSubview:alertView.addmoneyTextfield];
    alertView.addmoneyTextfield.textColor=[YZMAppStyle colorForBlackText];
    alertView.addmoneyTextfield.text=firstvalue.r2fString;
    alertView.addmoneyTextfield.font=[YZMAppStyle mediumSizeFont];
    alertView.addmoneyTextfield.layer.borderWidth = 0.5;
    alertView.addmoneyTextfield.layer.borderColor = [YZMAppStyle colorForGrayUnable].CGColor;
    alertView.addmoneyTextfield.layer.cornerRadius = 2;
    alertView.addmoneyTextfield.keyboardType = UIKeyboardTypeNumberPad;
    UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    alertView.addmoneyTextfield.leftView = blankView;
    [alertView.addmoneyTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.right.equalTo(yuan.mas_left);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondvalue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.right.equalTo(backView);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdstring;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = thirdvalue.r2fString;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.height.mas_equalTo(22);
        make.left.mas_equalTo(thirdLabel.mas_right).offset(10);
        make.right.equalTo(backView);
        make.centerY.equalTo(thirdLabel);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(thirdLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}

+(YZMAlertView *)addBondsAlertWithTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSNumber *)firstValue secondString:(NSString *)secondString secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue {
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue.r2fString;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondString;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    alertView.addmoneyTextfield=[YZMAppStyle inputTextField];
    [backView addSubview:alertView.addmoneyTextfield];
    alertView.addmoneyTextfield.textColor=[YZMAppStyle colorForBlackText];
    alertView.addmoneyTextfield.text=thirdValue.p2fString;
    alertView.addmoneyTextfield.font=[YZMAppStyle mediumSizeFont];
    alertView.addmoneyTextfield.layer.borderWidth = 0.5;
    alertView.addmoneyTextfield.layer.borderColor = [YZMAppStyle colorForGrayUnable].CGColor;
    alertView.addmoneyTextfield.layer.cornerRadius = 2;
    alertView.addmoneyTextfield.keyboardType = UIKeyboardTypeNumberPad;
    UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0)];
    alertView.addmoneyTextfield.leftView = blankView;
    [alertView.addmoneyTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(thirdLabel.mas_right).offset(10);
        make.right.equalTo(backView);
        make.centerY.equalTo(thirdLabel);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(thirdLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}

+(YZMAlertView *)alertViewForChangeDeferWithFristValue:(NSNumber *)firstValue withSecondValue:(NSNumber *)secondValue withFouthValue:(NSNumber *)fouthvalue withHoldDay:(NSNumber *)day withHint:(NSString *)hintText{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=@"期限续期";
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(5);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=@"点买金额:";
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
        make.height.mas_equalTo(14);
    }];
    
    alertView.addmoneyTextfield=[YZMAppStyle inputTextField];
    [backView addSubview:alertView.addmoneyTextfield];
    alertView.addmoneyTextfield.text=firstValue.r2fString;
    alertView.addmoneyTextfield.textColor=[YZMAppStyle colorForBlackText];
    alertView.addmoneyTextfield.font=[YZMAppStyle mediumSizeFont];
    alertView.addmoneyTextfield.borderStyle=UITextBorderStyleNone;
    [alertView.addmoneyTextfield setEnabled:NO];
    [alertView.addmoneyTextfield mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(171);
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel).offset(-4);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=@"履约保证金:";
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(14);
    }];
    
    UILabel *secondValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondValueLabel];
    secondValueLabel.text=secondValue.r2fString;
    secondValueLabel.textAlignment=NSTextAlignmentLeft;
    [secondValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(160);
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(14);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=@"递延时间:";
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(14);
    }];

    alertView.deferTimeLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.deferTimeLabel];
    alertView.deferTimeLabel.userInteractionEnabled=YES;
    alertView.deferTimeLabel.text=[NSString stringWithFormat:@"%@天", day];
    alertView.deferTimeLabel.layer.borderWidth=0.5;
    alertView.deferTimeLabel.layer.cornerRadius=2;
    alertView.deferTimeLabel.layer.masksToBounds=YES;
    alertView.deferTimeLabel.layer.borderColor=[YZMAppStyle colorForGrayUnable].CGColor;
    
    [alertView.deferTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(ScreenWidth*0.45);
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(thirdLabel.mas_right).offset(10);
        make.top.mas_equalTo(thirdLabel).offset(-4);
    }];
    
    UIImageView *arrowdownImageView=[[UIImageView alloc]init];
    [alertView.deferTimeLabel addSubview:arrowdownImageView];
    [arrowdownImageView setImage:[UIImage imageNamed:@"icon_triangle_down_gray"]];
    [arrowdownImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(alertView.deferTimeLabel).offset(7);
        make.right.mas_equalTo(alertView.deferTimeLabel).offset(-7);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(8);
    }];
    
    UIView *arrowLine=[YZMAppStyle splitLine];
    arrowLine.backgroundColor=[YZMAppStyle colorForGrayUnable];
    [alertView.deferTimeLabel addSubview:arrowLine];
    [arrowLine mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
    }];
    
    [arrowLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(alertView.deferTimeLabel);
        make.right.mas_equalTo(arrowdownImageView.mas_left).offset(-7);
        make.width.mas_equalTo(0.5);
    }];
    
    UILabel *fouthLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:fouthLabel];
    fouthLabel.text=@"递延费:";
    fouthLabel.textAlignment=NSTextAlignmentRight;
    [fouthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(thirdLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(14);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.deferLabel];
    alertView.deferLabel.text=fouthvalue.r2fString;
    alertView.deferLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(160);
        make.left.mas_equalTo(fouthLabel.mas_right).offset(10);
        make.top.mas_equalTo(thirdLabel.mas_bottom).offset(16);
        make.height.mas_equalTo(14);
    }];
    
    alertView.hintLabel = [YZMAppStyle labelWithFont:[YZMAppStyle smallSizeFont] andColor:[YZMAppStyle colorForRiseText]];
    alertView.hintLabel.adjustsFontSizeToFitWidth = YES;
    alertView.hintLabel.minimumScaleFactor = 0.1;
    alertView.hintLabel.text = hintText;
    [backView addSubview:alertView.hintLabel];
    [alertView.hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(backView);
        make.top.equalTo(alertView.deferLabel.mas_bottom).offset(10);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(alertView.hintLabel.mas_bottom);
    }];

    return alertView;
}



+ (YZMAlertView *)alertViewForStockSellMakeSureWithStock:(YZMSaleTradeModel *)stock andStockReal:(YZMStockRealModel*)stockReal andClickAction:(void (^)(BOOL selectdFlag))clickAction{
    
    YZMAlertView *alertView = [YZMAlertView new];
    alertView.titleLabel.text = @"点卖确认";
    
    UIView *customView = [UIView new];
    
    UIView *leftView = [UIView new];
    NSArray *leftArray = @[@"股票名称：", @"股票代码：",@"委托价格：",@"卖出数量：",@"持仓天数：",@"浮动盈亏："];
    
    UIView *lastView = nil;
    for (NSString *title in leftArray) {
        
        UILabel *label = [YZMAppStyle labelWithMediumGray];
        label.text = title;
        [leftView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(leftView);
            make.right.lessThanOrEqualTo(leftView);
            if (lastView) {
                
                make.top.equalTo(lastView.mas_bottom).offset(15);
            }else{
                
                make.top.equalTo(leftView);
            }
        }];
        
        lastView = label;
    }
    
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(lastView);
    }];
    
    UIView *rightView = [UIView new];
    double profit = (stockReal.price - stock.buyPriceDeal)*stock.holdCount;
    NSArray *rightArray = @[stock.stockName, [stock.stockCode substringFromIndex:2],@"市价",[NSString stringWithFormat:@"%@股",@(stock.holdCount)],[NSString stringWithFormat:@"%@天",@(stock.holdDays)],[NSString stringWithFormat:@"%@元", @(profit).p02fString]];
    
    lastView = nil;
    for (NSString *title in rightArray) {
        
        UILabel *label = [YZMAppStyle labelWithMediumGray];
        label.text = title;
        if (title == rightArray.lastObject) {
            
            [label setTextColorWithGreatNumber:profit andSmallNumber:0.0];
        }
        [rightView addSubview:label];
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.right.equalTo(rightView);
            make.left.greaterThanOrEqualTo(rightView);
            
            if (lastView) {
                
                make.top.equalTo(lastView.mas_bottom).offset(15);
            }else{
                
                make.top.equalTo(rightView);
            }
        }];
        
        lastView = label;
    }
    
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(lastView);
    }];
    
    [customView addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(customView);
    }];
    
    [customView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.right.equalTo(customView);
    }];
    
    UIButton *delayBT = [UIButton new];
    delayBT.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
    delayBT.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [delayBT setImage:[UIImage imageNamed:@"icon_choose_button"] forState:UIControlStateNormal];
    [delayBT setImage:[UIImage imageNamed:@"icon_choose_button_redselected"] forState:UIControlStateSelected];
    delayBT.selected = YES;
    [delayBT setTitle:@" 是否递延指令" forState:UIControlStateNormal];
    [delayBT setTitleColor:[YZMAppStyle colorForBlackText] forState:UIControlStateNormal];
    delayBT.titleLabel.font=[YZMAppStyle smallSizeFont];
    [delayBT bk_addEventHandler:^(id sender) {
        
        UIButton *bt = (UIButton *)sender;
        bt.selected = !bt.selected;
        
    } forControlEvents:UIControlEventTouchUpInside];
    
    [customView addSubview:delayBT];
    [delayBT mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(leftView.mas_bottom).offset(28);
        make.left.right.equalTo(customView);
    }];
    
    UILabel *recommandLB = [YZMAppStyle labelWithFont:[YZMAppStyle smallSizeFont] andColor:[YZMAppStyle colorForGrayText]];
    
    recommandLB.text = @"注:点卖指令可能因跌停导致无法成交，默认至下一个交易日挂单交易。浮动盈亏仅供参考，具体以实际成交为准。";
    recommandLB.numberOfLines = 0;
    [delayBT addSubview:recommandLB];
    [recommandLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(delayBT);
        make.top.equalTo(delayBT.mas_bottom).offset(2);
        make.right.equalTo(customView);
        make.bottom.mas_equalTo(customView.mas_bottom);
    }];
    
    alertView.customView = customView;
    alertView.confirmHandle = ^(){
        
        if (clickAction) {
            
            clickAction(delayBT.selected);
        }
        return YES;
    };
    
    return alertView;
}

+(YZMAlertView *)stopalertviewwitharray:(NSArray *)stopArray{
    
    YZMAlertView *alertView = [YZMAlertView new];
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=@"点卖确认";
    titleLabel1.textAlignment=NSTextAlignmentCenter;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.centerX.mas_equalTo(backView);
    }];
    
    UILabel *nameLabel=[YZMAppStyle labelWithMediumGray];
    nameLabel.text=@"股票名称:";
    [backView addSubview:nameLabel];
    nameLabel.textAlignment=NSTextAlignmentLeft;
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).offset(19);
        make.left.mas_equalTo(backView);
    }];
    
    UILabel *nameValueLabel=[YZMAppStyle labelWithMediumGray];
    nameValueLabel.text=stopArray[0];
    [backView addSubview:nameValueLabel];
    nameValueLabel.textAlignment=NSTextAlignmentRight;
    [nameValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(nameLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    UILabel *codeLabel=[YZMAppStyle labelWithMediumGray];
    codeLabel.text=@"股票代码";
    [backView addSubview:codeLabel];
    codeLabel.textAlignment=NSTextAlignmentLeft;
    [codeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(nameLabel);
        make.top.mas_equalTo(nameLabel.mas_bottom).offset(15);
    }];
    
    UILabel *codeValueLabel=[YZMAppStyle labelWithMediumGray];
    codeValueLabel.text=stopArray[1];
    [backView addSubview:codeValueLabel];
    codeValueLabel.textAlignment=NSTextAlignmentRight;
    [codeValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(codeLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    UILabel *priceLabel=[YZMAppStyle labelWithMediumGray];
    priceLabel.text=@"委托价格";
    [backView addSubview:priceLabel];
    priceLabel.textAlignment=NSTextAlignmentLeft;
    [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(nameLabel);
        make.top.mas_equalTo(codeLabel.mas_bottom).offset(15);
    }];
    
    UILabel *priceValueLabel=[YZMAppStyle labelWithMediumGray];
    priceValueLabel.text=@"市价";
    [backView addSubview:priceValueLabel];
    priceValueLabel.textAlignment=NSTextAlignmentRight;
    [priceValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(priceLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    UILabel *numberLabel=[YZMAppStyle labelWithMediumGray];
    numberLabel.text=@"卖出数量";
    [backView addSubview:numberLabel];
    numberLabel.textAlignment=NSTextAlignmentLeft;
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(nameLabel);
        make.top.mas_equalTo(priceLabel.mas_bottom).offset(15);
    }];
    
    UILabel *numberValueLabel=[YZMAppStyle labelWithMediumGray];
    numberValueLabel.text=[NSString stringWithFormat:@"%@股",stopArray[2]];
    [backView addSubview:numberValueLabel];
    numberValueLabel.textAlignment=NSTextAlignmentRight;
    [numberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(numberLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    UILabel *dayLabel=[YZMAppStyle labelWithMediumGray];
    dayLabel.text=@"持仓天数";
    [backView addSubview:dayLabel];
    dayLabel.textAlignment=NSTextAlignmentLeft;
    [dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(nameLabel);
        make.top.mas_equalTo(numberLabel.mas_bottom).offset(15);
    }];
    
    UILabel *dayValueLabel=[YZMAppStyle labelWithMediumGray];
    dayValueLabel.text=[NSString stringWithFormat:@"%@天",stopArray[3]];
    [backView addSubview:dayValueLabel];
    dayValueLabel.textAlignment=NSTextAlignmentRight;
    [dayValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(dayLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    
    UILabel *lastLabel=[YZMAppStyle labelWithMediumGray];
    lastLabel.text=@"浮动盈亏";
    [backView addSubview:lastLabel];
    lastLabel.textAlignment=NSTextAlignmentLeft;
    [lastLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(nameLabel);
        make.top.mas_equalTo(dayLabel.mas_bottom).offset(15);
    }];
    
    UILabel *lastValueLabel=[YZMAppStyle labelWithMediumGray];
    lastValueLabel.font=[YZMAppStyle mediumSizeBoldFont];
    lastValueLabel.text=[NSString stringWithFormat:@"%@元",stopArray[4]];
    [backView addSubview:lastValueLabel];
    lastValueLabel.textAlignment=NSTextAlignmentRight;
    [lastValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(lastLabel);
        make.right.mas_equalTo(backView.mas_right);
    }];
    [lastValueLabel setTextColorWithGreatNumber:[stopArray[4] doubleValue] andSmallNumber:0];
    
    alertView.choicebutton=[UIButton buttonWithType:UIButtonTypeCustom];
    [backView addSubview:alertView.choicebutton];
    alertView.choicebutton.adjustsImageWhenHighlighted=NO;
    [alertView.choicebutton setImage:[UIImage imageNamed:@"icon_choose_button"] forState:UIControlStateNormal];
    [alertView.choicebutton setImage:[UIImage imageNamed:@"icon_choose_button_redselected"] forState:UIControlStateSelected];
    [alertView.choicebutton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(lastLabel);
        make.top.mas_equalTo(lastLabel.mas_bottom).offset(30);
        make.height.width.mas_equalTo(16);
    }];
    
    UILabel *lasttextLabel=[YZMAppStyle labelWithSmallGray];
    [backView addSubview:lasttextLabel];
    lasttextLabel.numberOfLines=0;
    lasttextLabel.textAlignment=NSTextAlignmentLeft;
    lasttextLabel.text=@"是否递延指令（点卖指令可能因跌停导致无法成交，默认至下一个交易日挂单交易）";

    [lasttextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(lastLabel.mas_bottom).offset(30);
        make.left.mas_equalTo(lastLabel.mas_right).offset(-33);
        make.right.mas_equalTo(lastValueLabel);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(lasttextLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}


+(YZMAlertView *)sellStopwithTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSString *)firstValue secondString:(NSString *)secondstring secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    alertView.ruleBtn.hidden = NO;
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    [alertView.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(titleLabel1);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.width.equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    UILabel *thirdValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdValueLabel];
    thirdValueLabel.text=thirdValue.r2fString;
    thirdValueLabel.textAlignment=NSTextAlignmentLeft;
    [thirdValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(thirdLabel);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(thirdLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}


+ (YZMAlertView *)sellStopwithTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSString *)firstValue secondString:(NSString *)secondstring secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue info:(NSString *)info{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    alertView.ruleBtn.hidden = NO;
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    [alertView.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(titleLabel1);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(alertView.mas_left);
        make.right.equalTo(alertView.mas_right);
        make.top.equalTo(titleLabel1.mas_bottom).with.offset(10);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text= firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line1.mas_left).offset(10);
        make.width.mas_equalTo(131);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.equalTo(line1.mas_left).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.equalTo(line1.mas_left).offset(10);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    UILabel *thirdValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdValueLabel];
    thirdValueLabel.text=thirdValue.r2fString;
    thirdValueLabel.textAlignment=NSTextAlignmentLeft;
    [thirdValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(thirdLabel);
    }];
    
    UILabel *infoLabel =[YZMAppStyle labelWithMediumRise];
    [backView addSubview:infoLabel];
    infoLabel.text = info;
    infoLabel.textAlignment=NSTextAlignmentLeft;
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line1.mas_left).offset(35);
        make.right.equalTo(line1.mas_right).with.offset(-30);
        make.top.equalTo(thirdLabel.mas_bottom).with.offset(16);
    }];

    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(infoLabel.mas_bottom);
    }];
    
    return alertView;
}

+(YZMAlertView *)sellStopwithotherTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSString *)firstValue secondString:(NSString *)secondstring secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue withdeferValue:(NSNumber *)deferValue{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    UILabel *thirdValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdValueLabel];
    thirdValueLabel.textAlignment=NSTextAlignmentLeft;
    thirdValueLabel.text=thirdValue.r2fString;
    [thirdValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
        make.centerY.equalTo(thirdLabel);
    }];
    
    UILabel *deferValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:deferValueLabel];
    deferValueLabel.textAlignment=NSTextAlignmentCenter;
    NSString *deferString=[NSString stringWithFormat:@"(包含所欠递延费%@元)",deferValue.p2fString];
    NSMutableAttributedString *deferAttString=[[NSMutableAttributedString alloc]initWithString:deferString];
    [deferAttString addAttribute:NSForegroundColorAttributeName value:[YZMAppStyle colorForRiseText] range:NSMakeRange(8, deferValue.r2fString.length)];
    deferValueLabel.attributedText=deferAttString;
    [deferValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(thirdValueLabel.mas_bottom).offset(16);
        make.centerX.mas_equalTo(backView).offset(-30);
    }];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(deferValueLabel.mas_bottom).offset(0);
    }];
    
    return alertView;
}


+ (YZMAlertView *)showPayMakeSureWithBalance:(double)balance andPayMoney:(double)payMoney action:(BOOL(^)())action{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    alertView.confirmHandle = action;
    
    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor clearColor];
    [bgView mas_makeConstraints:^(MASConstraintMaker *maker){
        
    }];
    
    UIView *firstBgView = [UIView new];
    firstBgView.backgroundColor = [YZMAppStyle colorForLine];
    [bgView addSubview:firstBgView];
    [firstBgView mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.top.left.right.equalTo(bgView);
    }];
    
    UILabel *balanceLB = [UILabel new];
    balanceLB.text = @"账户余额(元):";
    balanceLB.textColor = [YZMAppStyle colorForGrayText];
    balanceLB.backgroundColor = [UIColor clearColor];
    balanceLB.font = [YZMAppStyle mediumSizeFont];
    balanceLB.textAlignment = NSTextAlignmentLeft;
    [firstBgView addSubview:balanceLB];
    [balanceLB mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.left.top.equalTo(firstBgView).offset(10);
        maker.bottom.equalTo(firstBgView).offset(-10);
        
    }];
    
    UILabel *balanceValueLB = [UILabel new];
    balanceValueLB.text = @(balance).decimalP02fString;
    balanceValueLB.textColor = [YZMAppStyle colorForGrayText];
    balanceValueLB.backgroundColor = [UIColor clearColor];
    balanceValueLB.font = [YZMAppStyle mediumSizeFont];
    balanceValueLB.textAlignment = NSTextAlignmentRight;
    balanceValueLB.minimumScaleFactor = 0.5;
    balanceValueLB.adjustsFontSizeToFitWidth = YES;
    [firstBgView addSubview:balanceValueLB];
    [balanceValueLB mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.left.equalTo(balanceLB.mas_right);
        maker.right.equalTo(firstBgView).offset(-10);
        maker.top.equalTo(balanceLB);
    }];
    
    
    UILabel *secondLB = [UILabel new];
    secondLB.textColor = [YZMAppStyle colorForGrayText];
    secondLB.backgroundColor = [UIColor clearColor];
    secondLB.font = [YZMAppStyle mediumSizeFont];
    secondLB.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:secondLB];
    [secondLB mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.top.equalTo(balanceLB.mas_bottom).offset(24);
        maker.left.equalTo(balanceLB);
    }];
    
    UILabel *secondValueLB = [UILabel new];
    secondValueLB.textColor = [YZMAppStyle colorForGrayText];
    secondValueLB.backgroundColor = [UIColor clearColor];
    secondValueLB.font = [YZMAppStyle mediumSizeFont];
    secondValueLB.textAlignment = NSTextAlignmentRight;
    secondValueLB.minimumScaleFactor = 0.5;
    secondValueLB.adjustsFontSizeToFitWidth = YES;
    [bgView addSubview:secondValueLB];
    [secondValueLB mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.left.equalTo(secondLB.mas_right);
        maker.right.equalTo(balanceValueLB);
        maker.top.equalTo(secondLB);
    }];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.bottom.equalTo(secondLB).offset(5);
    }];
    
    if ([@(balance) isEqualGreaterThanDouble:payMoney]) {
        
        /*余额足够时，提示用户扣款信息*/
        [secondLB setText:@"本次支付(元):"];
        [secondValueLB setText:@(payMoney).decimalP02fString];
        
        alertView.titleLabel.text = @"确认支付";
        alertView.customView = bgView;
        alertView.tag = 0;
    
        secondValueLB.textColor = [YZMAppStyle colorForRiseText];
    }else{
        
        /*余额不足时，提示用户余额不足*/
        [secondLB setText:@"还需充值(元):"];
        [secondValueLB setText:@(payMoney - balance).decimalP02fString];
        
        alertView.titleLabel.text = @"账户余额不足";
        [alertView.sureButton setTitle:@"充值" forState:UIControlStateNormal];
        alertView.customView = bgView;
        alertView.tag = 1;
    }
    
    [alertView show];
    
    return alertView;
}

#pragma mark -- Event Response
- (void)clickToMakeSure:(UIButton *)sender{
    
    if (self.confirmHandle) {
        
        if (self.confirmHandle()) {
            
            [self dismissWithAnimationFlag:YES];
        }
    }else{
        
        [self dismissWithAnimationFlag:YES];
    }
}

- (void)clickToCancel:(UIButton *)sender{
    
    [self dismissWithAnimationFlag:YES];
    
    if (self.cancleHandle) {
        
        self.cancleHandle();
    }
}

#pragma mark -- Private Method

- (void)createObjects{
    
    self.backgroundColor = [UIColor colorWithRed: 0 green:0 blue:0 alpha:0.5];
    _containerView = [UIView new];
    _containerView.layer.cornerRadius = 5.0;
    _containerView.layer.masksToBounds = YES;
    _containerView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_containerView];
    
    self.titleLabel = [UILabel new];
    self.titleLabel.textColor = [YZMAppStyle colorForBlackText];
    self.titleLabel.font = [YZMAppStyle largeSizeBoldFont];
    [_containerView addSubview: self.titleLabel];
    
    self.ruleBtn = [UIButton new];
    [self.ruleBtn setTitle:@"停牌股处理细则" forState:UIControlStateNormal];
    [self.ruleBtn.titleLabel setFont:[YZMAppStyle mediumSizeFont]];
    [self.ruleBtn setTitleColor:[YZMAppStyle colorForLightBlueText] forState:UIControlStateNormal];
    self.ruleBtn.hidden = YES;
    [self.ruleBtn addTarget:self action:@selector(ruleAction:) forControlEvents:UIControlEventTouchUpInside];

    [_containerView addSubview:self.ruleBtn];
    
    self.contentLabel = [UILabel new];
    self.contentLabel.textColor = [YZMAppStyle colorForGrayText];
    self.contentLabel.font = [YZMAppStyle mediumSizeFont];
    self.contentLabel.numberOfLines = 0;
    [_containerView addSubview: self.contentLabel];
    
    self.footLabel = [UILabel new];
    self.footLabel.textColor = [YZMAppStyle colorForLightGrayText];
    self.footLabel.font = [YZMAppStyle smallSizeFont];
    [_containerView addSubview: self.footLabel];
    self.footLabel.numberOfLines = 0;
    
    self.sureButton = [UIButton new];
    [self.sureButton setTitle:@"确定" forState:UIControlStateNormal];
    [self.sureButton setTitleColor:[YZMAppStyle colorForRiseText] forState:UIControlStateNormal];
    [self.sureButton.titleLabel setFont:[YZMAppStyle largeSizeFont]];
    [self.sureButton addTarget:self action:@selector(clickToMakeSure:) forControlEvents:UIControlEventTouchUpInside];
    [_containerView addSubview:self.sureButton];
    
    self.cancelButton = [UIButton new];
    [self.cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelButton setTitleColor:[YZMAppStyle colorForRiseText] forState:UIControlStateNormal];
    [self.cancelButton.titleLabel setFont:[YZMAppStyle largeSizeFont]];
    [self.cancelButton addTarget:self action:@selector(clickToCancel:) forControlEvents:UIControlEventTouchUpInside];
    [_containerView addSubview:self.cancelButton];
}

- (void)assignConstaints{
    
    UIView *lastView = nil;
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_containerView).with.offset(alert_view_margin_left);
        make.centerX.equalTo(_containerView);
    }];
    
    [self.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_containerView).offset(-10);
    }];
    
    lastView = self.titleLabel;
    
    if (self.contentLabel.text.length != 0) {
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).with.offset(15);
            make.left.equalTo(_containerView).offset(alert_view_margin_left);
            make.right.equalTo(_containerView).with.offset(-alert_view_margin_left);
        }];
        
        lastView = self.contentLabel;
    }else{
        
        self.contentLabel.hidden = YES;
    }
    
    if (self.footLabel.text && self.footLabel.text.length != 0) {
        
        [self.footLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.contentLabel.mas_bottom).with.offset(15);
            make.leading.equalTo(self.titleLabel);
            make.trailing.equalTo(_containerView).with.offset(-alert_view_margin_left);
            make.bottom.equalTo(_containerView).with.offset(-alert_view_margin_left);
        }];
        
        lastView = self.footLabel;
        
    }else{
        
        self.footLabel.hidden = YES;
    }
    
    if (self.customView) {
        
        [self.customView mas_makeConstraints:^(MASConstraintMaker *maker){
            
            maker.top.equalTo(lastView.mas_bottom).offset(15);
            maker.left.equalTo(_containerView).offset(alert_view_margin_left);
            maker.right.equalTo(_containerView).offset(-alert_view_margin_left);
            maker.centerX.equalTo(_containerView);
        }];
        
        lastView = self.customView;
    }
    {
        /*分割线*/
        UIView *line = [UIView new];
        line.backgroundColor = [YZMAppStyle colorForLine];
        [_containerView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *maker){
            
            maker.left.right.equalTo(_containerView);
            maker.top.equalTo(lastView.mas_bottom).offset(20);
            maker.height.mas_equalTo(0.5);
        }];
        
        lastView = line;
    }
    
    if (!self.cancelButton.hidden) {
        
        [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *maker){
            
            maker.top.equalTo(lastView.mas_bottom);
            maker.height.mas_equalTo(44);
            maker.width.equalTo(_containerView).dividedBy(2);
            maker.left.equalTo(_containerView);
        }];
        
        lastView = self.cancelButton;
    }
    
    {
        if (lastView == self.cancelButton) {
            
            [self.sureButton mas_makeConstraints:^(MASConstraintMaker *maker){
                
                maker.top.height.width.equalTo(lastView);
                maker.left.equalTo(lastView.mas_right);
            }];
            
            UIView *line = [UIView new];
            line.backgroundColor = [YZMAppStyle colorForLine];
            [_containerView addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *maker){
                
                maker.width.mas_equalTo(0.5);
                maker.centerX.equalTo(self.sureButton.mas_left);
                maker.top.height.equalTo(self.sureButton);
            }];
            
        }else{
            
            [self.sureButton mas_makeConstraints:^(MASConstraintMaker *maker){
                
                maker.top.equalTo(lastView.mas_bottom);
                maker.height.mas_equalTo(44);
                maker.width.equalTo(_containerView);
                maker.centerX.equalTo(_containerView);
            }];
        }
        
        lastView = self.sureButton;
    }
    
    [_containerView mas_makeConstraints:^(MASConstraintMaker *maker){
        
        maker.width.equalTo(self).offset(-40);
        maker.centerX.centerY.equalTo(self);
        maker.bottom.equalTo(lastView);
    }];
}


+(YZMAlertView *)sellStopwithTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSString *)firstValue secondString:(NSString *)secondstring secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue withLossValue:(NSNumber *)lossValue{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    alertView.ruleBtn.hidden = NO;
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    [alertView.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(titleLabel1);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];

    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    UILabel *thirdValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdValueLabel];
    thirdValueLabel.text=thirdValue.r2fString;
    thirdValueLabel.textAlignment=NSTextAlignmentLeft;
    [thirdValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(thirdLabel);
    }];
    
    UILabel *lossLabel=[YZMAppStyle labelWithMediumGray];
    [backView addSubview:lossLabel];
    lossLabel.textColor=[YZMAppStyle colorForRiseText];
    [lossLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(backView);
        make.top.equalTo(thirdLabel.mas_bottom).offset(7);
    }];
    lossLabel.text=[NSString stringWithFormat:@"(保证金%@元，将在买断时自动抵扣)",lossValue.r2fString];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(lossLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}

+(YZMAlertView *)sellStopwithotherTitle:(NSString *)title withFirstString:(NSString *)firstString firstValue:(NSString *)firstValue secondString:(NSString *)secondstring secondValue:(NSNumber *)secondValue thirdString:(NSString *)thirdString thirdValue:(NSNumber *)thirdValue withdeferValue:(NSNumber *)deferValue withLossValue:(NSNumber *)lossValue{
    
    YZMAlertView *alertView = [YZMAlertView new];
    
    alertView.ruleBtn.hidden = NO;
    UIView *backView=[UIView new];
    alertView.customView=backView;
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UILabel *titleLabel1=[YZMAppStyle labelWithLargeBlack];
    [backView addSubview:titleLabel1];
    titleLabel1.text=title;
    titleLabel1.textAlignment=NSTextAlignmentLeft;
    [titleLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(backView).offset(-20);
        make.left.mas_equalTo(backView);
    }];
    
    [alertView.ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(titleLabel1);
    }];
    
    UIView *line1=[YZMAppStyle splitLine];
    [backView addSubview:line1];
    line1.backgroundColor=[YZMAppStyle colorForLine];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel1.mas_bottom).mas_equalTo(10);
        make.left.mas_equalTo(alertView);
        make.width.mas_equalTo(alertView);
    }];
    
    UILabel *firstLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:firstLabel];
    firstLabel.text=firstString;
    firstLabel.textAlignment=NSTextAlignmentRight;
    [firstLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(line1.mas_bottom).offset(30);
    }];
    
    alertView.deferLabel=[YZMAppStyle labelWithMediumBlack];
    alertView.deferLabel.text = firstValue;
    [backView addSubview:alertView.deferLabel];
    [alertView.deferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(22);
        make.left.mas_equalTo(firstLabel.mas_right).offset(10);
        make.centerY.equalTo(firstLabel);
    }];
    
    UILabel *secondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:secondLabel];
    secondLabel.textAlignment=NSTextAlignmentRight;
    secondLabel.text=secondstring;
    [secondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
    }];
    
    alertView.bondLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:alertView.bondLabel];
    alertView.bondLabel.text=secondValue.r2fString;
    alertView.bondLabel.textAlignment=NSTextAlignmentLeft;
    [alertView.bondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(firstLabel.mas_bottom).offset(16);
        make.centerY.equalTo(secondLabel);
    }];
    
    UILabel *thirdLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdLabel];
    thirdLabel.text=thirdString;
    thirdLabel.textAlignment=NSTextAlignmentRight;
    [thirdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(131);
        make.left.mas_equalTo(line1);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
    }];
    
    UILabel *thirdValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:thirdValueLabel];
    thirdValueLabel.textAlignment=NSTextAlignmentLeft;
    thirdValueLabel.text=thirdValue.p2fString;
    [thirdValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(secondLabel.mas_right).offset(10);
        make.top.mas_equalTo(secondLabel.mas_bottom).offset(16);
        make.centerY.equalTo(thirdLabel);
    }];
    
    UILabel *deferValueLabel=[YZMAppStyle labelWithMediumBlack];
    [backView addSubview:deferValueLabel];
    deferValueLabel.textAlignment=NSTextAlignmentCenter;
    NSString *deferString=[NSString stringWithFormat:@"(包含所欠递延费%@元)",deferValue.p2fString];
    NSMutableAttributedString *deferAttString=[[NSMutableAttributedString alloc]initWithString:deferString];
    [deferAttString addAttribute:NSForegroundColorAttributeName value:[YZMAppStyle colorForRiseText] range:NSMakeRange(8, deferValue.r2fString.length)];
    deferValueLabel.attributedText=deferAttString;
    [deferValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(thirdValueLabel.mas_bottom).offset(16);
        make.centerX.mas_equalTo(backView).offset(-30);
    }];
    
    UILabel *lossLabel=[YZMAppStyle labelWithMediumGray];
    [backView addSubview:lossLabel];
    lossLabel.textColor=[YZMAppStyle colorForRiseText];
    [lossLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(backView);
        make.top.equalTo(deferValueLabel.mas_bottom).offset(7);
    }];
    lossLabel.text=[NSString stringWithFormat:@"(保证金%@元，将在买断时自动抵扣)",lossValue.r2fString];
    
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(lossLabel.mas_bottom).offset(10);
    }];
    
    return alertView;
}

- (void)setCustomView:(UIView *)customView{
    
    if (_customView) {
        
        [_customView removeFromSuperview];
    }
    _customView = customView;
    [_containerView addSubview:_customView];
}

- (void)showInView: (UIView *)view{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasHide:) name:UIKeyboardWillHideNotification object:nil];
    self.alpha = 0;
    [view addSubview: self];
    self.frame = view.bounds;
    [self assignConstaints];
    [UIView animateWithDuration: .4 animations:^{
        
        self.alpha = 1;
    }];
}

- (void)show{
    
    UIView *view = [[YZMControllerManager sharedManager] currentNavationCtroller].view;
    [self showInView: view];
}

- (void)dismissWithAnimationFlag:(BOOL)animation{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    if (animation) {
        
        self.alpha = 1;
        [UIView animateWithDuration: .4f animations:^{
            self.alpha = 0.0;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }else{
        
        [self removeFromSuperview];
    }
}

- (void)animationMoveUpWithKeyboardHeight:(float)keyboardHeight{
    
    float contentBottomY = _containerView.frame.origin.y + _containerView.frame.size.height;
    float keyboardTopY = self.frame.size.height - keyboardHeight;
    
    float distance = contentBottomY - keyboardTopY+20;
    
    if (distance >0) {
        
        [_containerView mas_updateConstraints:^(MASConstraintMaker *maker){
            
            maker.centerY.equalTo(self).offset(-distance);
        }];
        
        [UIView animateWithDuration:0.2 animations:^{
            
            [self layoutIfNeeded];
        }];
        
        _hasMoveFlag = YES;
    }
}

- (void)animationMoveDown{
    
    if (!_hasMoveFlag) {
        
        return;
    }
    
    [_containerView mas_updateConstraints:^(MASConstraintMaker *maker){
        
        maker.centerY.equalTo(self);
    }];
    
    [UIView animateWithDuration:0.2 animations:^{
        
        [self layoutIfNeeded];
        
    }];
    
    _hasMoveFlag = NO;
}

-(void)ruleAction:(UIButton *)sender{

    [self dismissWithAnimationFlag:YES];
    if (self.ruleBlock) {
        self.ruleBlock();
    }
}

#pragma mark -- touch

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self endEditing:YES];
}

@end
